package com.example.a04;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

public class IntentDemoActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 获取按钮控件
        Button button = findViewById(R.id.button);

        // 为按钮设置点击事件
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 创建显式Intent，指定目标Activity为NewActivity
                Intent intent = new Intent(IntentDemoActivity.this, NewActivity.class);
                // 启动Activity
                startActivity(intent);
            }
        });
    }
}